<template>
    <!-- 搜索区域 -->
    <div style="display: flex">
        <el-input v-model="searchCourseName" placeholder="请输入课程名称"
                  style="width: 200px;height: 33px;margin-right: 15px;font-size: 15px;" clearable></el-input>
        <el-input v-model="searchPeriodName" placeholder="请输入课时名称"
                  style="width: 200px;height: 33px;margin-right: 15px;font-size: 15px;" clearable></el-input>
        <el-select style="width: 200px;margin-right: 15px" placeholder="请选择课时进度" v-model="searchFlow" clearable>
            <el-option
                    v-for="item in flowOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
        </el-select>
        <el-button type="primary" style="color: #fff;font-size: 12px;background-color: #1890ff;" @click="load">搜索
        </el-button>
    </div>

    <!-- 表格区域 -->
    <el-table :data="tableData" :row-style="{ height: '77px' }" border
              style="width: calc(100vw - 240px);margin-top: 20px;height: 70vh;color: #909399;font-size: 15px;">
        <el-table-column align="center" prop="courseName" label="课程名称"/>
        <el-table-column align="center" prop="periodName" label="课时名称"/>
        <el-table-column align="center" prop="username" label="学员姓名"/>
        <el-table-column align="center" prop="createTime" label="签到时间" sortable/>
        <el-table-column prop="photo" label="照片" align="center">
            <template v-slot="scope">
                <el-image style="width: 100px; height: 100px" :src="scope.row.photo"
                          :preview-src-list="[scope.row.photo]"></el-image>
            </template>
        </el-table-column>
        <el-table-column prop="url" label="手签" align="center">
            <template v-slot="scope">
                <el-image style="width: 100px; height: 100px" :src="scope.row.url"
                          :preview-src-list="[scope.row.url]"></el-image>
            </template>
        </el-table-column>
        <el-table-column align="center" prop="flow" label="课时进度">
            <template v-slot="scope">
                <el-tag type="warning" v-if="scope.row.flow === 0">未完成</el-tag>
                <el-tag type="success" v-else-if="scope.row.flow === 1">已完成</el-tag>
            </template>
        </el-table-column>
    </el-table>

    <!-- 分页区域 -->
    <div style="margin-top: 10px">
        <el-pagination
                :current-page="currentPage"
                :page-size="pageSize"
                :page-sizes="[10, 20, 30, 50]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :background="true"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        />
    </div>
</template>

<script>
    import request from "~/utils/request.js";

    export default {
        data() {
            return {
                tableData: [],
                searchUsername: '',
                searchCourseName: '',
                searchPeriodName: '',
                searchFlow: '',
                stuId: this.$store.state.user.id,
                flowOptions: [
                    {value: 0, label: '未完成'},
                    {value: 1, label: '已完成'},
                ],
                currentPage: 1,
                pageSize: 10,
                total: 0,
            }
        },
        created() {
            this.load()
        },
        activated() {
            this.load()
        },
        methods: {
            load() {
                request.get("/train-sign/page?pageNum=" + this.currentPage + "&pageSize=" + this.pageSize + "&username=" + this.searchUsername + "&courseName=" + this.searchCourseName + "&periodName=" + this.searchPeriodName + "&flow=" + this.searchFlow + "&stuId=" + this.stuId).then(res => {
                    if (res.code === '200') {
                        this.tableData = res.data.records
                        this.total = res.data.total
                    } else {
                        ElMessage.error("错误" + res.msg)
                    }
                })
            },
            handleCurrentChange(item) {
                // 改变当前页码触发
                this.currentPage = item
                this.load()
            },
            handleSizeChange(item) {   // 改变当前每页的个数触发
                this.pageSize = item
                this.load()
            },
        }
    }
</script>

<style scoped>
    /* Add your styles here */
</style>
